(define counter (box 0))

(define (between min max)
  (if (> min max)
      '()
      (cons min (between (+ min 1) max))))

(define (partitions-> min n l)
  (if (> min n)
      (if (= n 0)
          (begin
            (set-box! counter (+ (unbox counter) 1))
            (print l))
          #f)
      (for-each (lambda (k)
                  (partitions-> k (- n k) (cons k l)))
        (between min n))))

(define (partitions n)
  (display "partitions of ")
  (print n)

  (set-box! counter 0)
  (partitions-> 1 n '())

  (display (unbox counter))
  (print " partitions!"))

;; 627
(partitions 20)
